/*-------------------------------------------------------------------------
 *
 * clogdesc.c
 *	  访问/transam/clog.c 的 rmgr 描述例程
 *
 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  src/backend/access/rmgrdesc/clogdesc.c
 *
 *-------------------------------------------------------------------------
 */
#include "postgres.h"

#include "access/clog.h"


void clog_desc(StringInfo fc_buf, XLogReaderState *fc_record)
{
	char	   *fc_rec = XLogRecGetData(fc_record);
	uint8		fc_info = XLogRecGetInfo(fc_record) & ~XLR_INFO_MASK;

	if (fc_info == CLOG_ZEROPAGE)
	{
		int			fc_pageno;

		memcpy(&fc_pageno, fc_rec, sizeof(int));
		appendStringInfo(fc_buf, "page %d", fc_pageno);
	}
	else if (fc_info == CLOG_TRUNCATE)
	{
		xl_clog_truncate fc_xlrec;

		memcpy(&fc_xlrec, fc_rec, sizeof(xl_clog_truncate));
		appendStringInfo(fc_buf, "page %d; oldestXact %u",
						 fc_xlrec.pageno, fc_xlrec.oldestXact);
	}
}

const char * clog_identify(uint8 fc_info)
{
	const char *fc_id = NULL;

	switch (fc_info & ~XLR_INFO_MASK)
	{
		case CLOG_ZEROPAGE:
			fc_id = "ZEROPAGE";
			break;
		case CLOG_TRUNCATE:
			fc_id = "TRUNCATE";
			break;
	}

	return fc_id;
}
